<?xml version="1.0" encoding="UTF-8"?>
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:p="http://primefaces.org/ui"
	template="/WEB-INF/templates/default.xhtml"
	xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">

	<f:metadata>
		<f:viewParam name="moduleName" value="按中介机构统计"></f:viewParam>
	</f:metadata>
	<ui:define name="head">
		<h:outputStylesheet name="css/public/tab.css" />
		<h:outputStylesheet name="css/public/table.css" />
		<script>
		
		</script>
	</ui:define>
	<ui:define name="content">
		<h:form>
			<div style="margin: 10px auto;">
				<p:outputLabel value="入驻日期：" style="display:inline-bloack;margin-top:10px;"></p:outputLabel>
				<p:calendar  styleClass="startDate" locale="zh_CN"
					navigator="true" pattern="yyyy-MM-dd" value="#{serviceSupplierList.startDate}" />
				至
				<p:calendar  styleClass="endDate"	locale="zh_CN"
					navigator="true" pattern="yyyy-MM-dd" value="#{serviceSupplierList.endDate}"/>
				<p:outputLabel value=" 资质范围：" style="display:inline-bloack; "></p:outputLabel>
				<p:outputLabel>
					<p:selectOneMenu styleClass="qualificationClassId" widgetVar="qualificationClassId"
						value="#{qualificationConditionBean.qualificationClassId}">
						<f:selectItem itemLabel="--请选择--" itemValue="#{null}" />
						<f:selectItems value="#{qualificationClassList.resultList}"
							var="_class" itemLabel="#{_class.name}" itemValue="#{_class.id}">
						</f:selectItems>
						<f:ajax render="sectorId certLevel"></f:ajax>
					</p:selectOneMenu>#{' '}
							<p:selectOneMenu id="sectorId" widgetVar="sectorId" styleClass="sectorId"
						value="#{qualificationConditionBean.sectorId}">
						<f:selectItem itemLabel="--请选择--" itemValue="#{null}" />
						<f:selectItems value="#{qualificationConditionBean.sectors}"
							var="_sector" itemLabel="#{_sector.sectorName}"
							itemValue="#{_sector.id}"></f:selectItems>
						<f:ajax event="change"
							listener="#{qualificationConditionBean.initChildSectors()}"
							render="childSectorId"></f:ajax>
					</p:selectOneMenu>

					<p:selectOneMenu id="childSectorId" widgetVar="childSectorId" styleClass="childSectorId"
						value="#{qualificationConditionBean.childSectorSno}">
						<f:selectItem itemLabel="--请选择--" itemValue="#{null}" />
						<f:selectItems value="#{qualificationConditionBean.childSectors}"
							var="_childsector" itemLabel="#{_childsector.sectorName}"
							itemValue="#{_childsector.sno}"></f:selectItems>
					</p:selectOneMenu>
					#{ ' '}
					<p:commandButton value="查询" styleClass="queryBtn" ></p:commandButton>
					#{ ' '}
					<p:commandButton value="重置"  ajax="false"
						action="SupplierStat.xhtml"></p:commandButton>	
				</p:outputLabel>
			</div>
			<p:commandButton value="导出" ajax="false" style="margin:10px;">
	   			<p:fileDownload value="#{statExport.suppierStatExport()}" />
	   		</p:commandButton>
			<table border="1" class="reqTable table" >
				<thead>
					<tr>
						<th rowspan="2" width="40">序号</th>
						<th rowspan="2" width="40%">中介机构</th>
						<th rowspan="2">报名次数</th>
						<th colspan="6">中选次数</th>
					</tr>
					<tr>
						<th>合计</th>
						<th>随机选取</th>
						<th>择优选取</th>
						<th>竞价选取</th>
						<th>均价选取</th>
						<th>直接选取</th>
					</tr>
				</thead>
				<tbody>
				</tbody>
			</table>
			<div id="page" class="page_div"></div>
		</h:form>
		<script type="text/javascript">
			var contextPath = '${request.getContextPath()}';
			var pageSize = 10;
		//生成表格
			$(function(){	
				$(".queryBtn").click(function(){
					init();
				});	
				init();
			})
			// <![CDATA[
			function init(){
				var totalCount = serviceSupplierStat(1,contextPath);	
				generatePage(totalCount);
			}
			function serviceSupplierStat(pageNumber,contextPath){
				var startDate = $(".startDate").find("input").val();
			 	var endDate = $(".endDate").find("input").val();
			 	var qualificationClassId = PF('qualificationClassId').getSelectedValue();
			 	var sectorId = PF('sectorId').getSelectedValue();
			 	var childSectorId = PF('childSectorId').getSelectedValue();
				var totalCount = 0;
				var url = contextPath+"/rest/serviceSupplier/getServiceSupplierStat?pageSize="+pageSize+"&pageNumber="+pageNumber
						+"&startDate="+startDate+"&endDate="+endDate+"&qualificationClassId="+qualificationClassId+"&sectorId="+sectorId+"&childSectorId="+childSectorId;
				$.ajax({
					url:url,
					async:false,
					success:function(data){
						var html = "";
						totalCount = data["totalCount"];
						var list = data["list"];
						for(var index in list){
							var supplier = list[index];
							html += "<tr>";
								html +="<td>"+ (parseInt(index) + 1)+"</td>";
								html +="<td>"+supplier.cnname+"</td>";
								html +="<td>"+supplier.appliedCount+"</td>";
								html +="<td>"+supplier.successCount+"</td>";
								html +="<td>"+supplier.randomSuccessCount+"</td>";
								html +="<td>"+supplier.bestSuccessCount+"</td>";
								html +="<td>"+supplier.priceSuccessCount+"</td>";
								html +="<td>"+supplier.averageSuccessCount+"</td>";
								html +="<td>"+supplier.manualSuccessCount+"</td>";
							html += "</tr>";
						}
						$(".reqTable").find("tbody").html(html);
						
					}
				});
				return totalCount;
			}
			function generatePage(totalCount){
				 //分页js
				 $("#page").paging({
					 pageNo:1,
				     totalPage: Math.ceil(totalCount/pageSize),
				     totalSize: totalCount,
				     callback: function(pageNumber) {
				    	 serviceSupplierStat(pageNumber,contextPath);
				     }
				 })
			}
			// ]]>
		</script>
	</ui:define>
</ui:composition>